package com.yunmouren.webkit.Engine;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.AnchorPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

@net.fabricmc.api.Environment(net.fabricmc.api.EnvType.CLIENT)
public class Engine extends Application {
    public WebView browser;
    public WebEngine webEngine;

    public void onInitialize() {
        this.browser = new WebView();
        this.webEngine = this.browser.getEngine();
    }

    public void LoadUrl(String url) {
        this.webEngine.load(url);
    }

    public WebView show() {
        return this.browser;
    }
    /**
     * 启动
     * @param stage 画板
     */
    @Override
    public void start(Stage stage) {
        AnchorPane root = new AnchorPane();
        Scene scene = new Scene(root, 1920, 1080);
        onInitialize();
//        初始化引擎
        ScrollPane scrollPane = new ScrollPane(show());
//        将引擎绑定到画板
        show().setMinWidth(scene.getWidth());
        show().setMinHeight(scene.getHeight());

        scrollPane.setPrefSize(scene.getWidth(), scene.getHeight());
//        设置引擎
        root.getChildren().add(scrollPane);
//        绑定至显示
        LoadUrl("https://www.testufo.com/");
//        加载路由
        stage.setScene(scene);
        stage.show();

    }
    public void stop(){

    }
    @net.fabricmc.api.Environment(net.fabricmc.api.EnvType.CLIENT)
    public static void main() {
        launch();
    }

}
